import generator
import alg
import time
import numpy as np
import matplotlib.pyplot as plt
def runtime(func,data):
    start=time.perf_counter()
    func(data)
    end=time.perf_counter()
    return end-start
def runtime2(func,data,k):
    start=time.perf_counter()
    func(data,k)
    end=time.perf_counter()
    return end-start
a=generator.generator(4,4000)
b=generator.generator(4,6000)
c=generator.generator(4,8000)
d=generator.generator(4,10000)
Listtime1=[]
Listtime2=[]
Listtime3=[]
Listtime4=[]
Listdata=[]#总数据集
Listdata.append(Listtime1)
Listdata.append(Listtime2)
Listdata.append(Listtime3)
Listdata.append(Listtime4)
for i in range(4):
    Listdata[i].append(a[i])
    Listdata[i].append(b[i])
    Listdata[i].append(c[i])
    Listdata[i].append(d[i])
List1=[]
List2=[]
List3=[]
List4=[]
List5=[]#定义五个列表存放五个算法运行时间
for i in range(4):
    List1.append(runtime(alg.reversePairs,Listdata[0][i]))
    List2.append(runtime(alg.reversePairsn, Listdata[1][i]))
    List3.append(runtime(alg.majorityElement, Listdata[2][i]))
    List4.append(runtime2(alg.findKthLargest, Listdata[3][i],2))
print(List1)
print(List2)
print(List3)
print(List4)

#定义四个矩阵 5X5 50X50,500X500,5000X5000
M1=np.random.randint(100,999,size=[30,30])
M2=np.random.randint(1000,9999,size=[90,90])
M3=np.random.randint(10000,99999,size=[200,200])
M4=np.random.randint(100000,999999,size=[900,900])
List5.append(runtime2(alg.searchMatrix,M2,125))
List5.append(runtime2(alg.searchMatrix,M2,2500))
List5.append(runtime2(alg.searchMatrix,M2,25000))
List5.append(runtime2(alg.searchMatrix,M2,250000))
print(List5)